<?php
namespace app\classes\helper;
use think\Db;
use think\facade\Env;

class Paymihua
{
    // 米花支付-验证签名解密数据
    public function newMhCheckSign($encodeData,$config)
    {
        include_once('../extend/MiHuaApi/config.php');
        include_once('../extend/MiHuaApi/getSign.php');
        include_once('../extend/MiHuaApi/getData.php');

        $publicKey   = $config['public_key'];
        $res         = decryptData($encodeData, $publicKey);
        $decryptData = json_decode($res, true);
        if (checkMhSign($decryptData, $publicKey)) {
            return $decryptData;
        } else {
            return array();
        }
    }

    // 米花支付查询订单更详细的信息
    public function newMhGetOrder($decryptData,$config)
    {
        include_once('../extend/MiHuaApi/config.php');
        include_once('../extend/MiHuaApi/getSign.php');
        include_once('../extend/MiHuaApi/getData.php');

        // 订单查询
        $orderData = array(
            'merAccount' => $config['mer_account'],
            'orderId'    => $decryptData['orderId'],
            'time'       => time(),
        );
        // 生成签名
        $privateKey        = $config['private_key'];
        $orderData['sign'] = getMhSign($orderData, $privateKey);
        $encodeData        = encryptData($orderData, $privateKey);
        $postData          = array(
            'merAccount' =>  $config['mer_account'], // 商户标识
            'data'       => $encodeData,
        );
        $api_url = \MiHuaPayConfig::API_URL_GET_ORDER;
        $res     = httpPost($api_url, http_build_query($postData));
        return json_decode($res, true);
    }


}